# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: PumpkinCheshire <me at pumpkincheshire dot com>
# Contributor: Cobalt Space <cobaltspace at protonmail dot com>
# Contributor: Mitch Bigelow <ipha00 at gmail dot com>

pkgname=ncnn
pkgver=20230816
pkgrel=3
pkgdesc='High-performance neural network inference framework optimized for the mobile platform'
url='https://github.com/Tencent/ncnn'
arch=('loong64' 'x86_64')
license=('BSD')
depends=('vulkan-icd-loader')
makedepends=('cmake' 'glslang' 'ninja' 'protobuf' 'vulkan-headers')
optdepends=('protobuf: for onnx2ncnn')
conflicts=('ncnn-git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/Tencent/ncnn/archive/$pkgver.tar.gz"
        $pkgname-protobuf-23.patch::https://github.com/Tencent/ncnn/commit/cd1c0d6eab505ce71a4cb1ed6b017609dbb80ffd.patch)
b2sums=('0dcc563d28d6e3e6784c3db3a6d434af478b294d1f79109026172264de7006116f8eefbf10f4f136dc9447488c0555b42f8336c57460c71e74c267229a2e7aab'
        'af35a475048e1292544e6d6e3044e00e26932a9e27b2f386206e4e0f85887d10005acff2a5e3bf6c04f1d41657ac60c1e64cea554cc3c93cde07af3f37c3a5e8')

prepare() {
    cd "$pkgname-$pkgver"
    patch -p1 -i ../$pkgname-protobuf-23.patch
}

build() {
    cmake -B build -S "$pkgname-$pkgver" \
        -GNinja \
        -DCMAKE_BUILD_TYPE='None' \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DNCNN_SHARED_LIB=ON \
        -DNCNN_ENABLE_LTO=ON \
        -DNCNN_VULKAN=ON \
        -DNCNN_SYSTEM_GLSLANG=ON \
        -DNCNN_BUILD_EXAMPLES=OFF \
        -DGLSLANG_TARGET_DIR=/usr/lib/cmake \
        -Wno-dev
    ninja -C build
}

package() {
    DESTDIR="$pkgdir" ninja -C build install
    install -Dm644 "$srcdir"/ncnn-$pkgver/LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
